#include <string.h>
#include <stdio.h>
#include "PersonBase.h"

PersonBase::PersonBase(int id, PersonRights rights)
    : m_id(id)
    , m_rights(rights)
{
    memset(m_name, 0, sizeof(m_name));
}

PersonBase::PersonBase(int id, const char* name, int namelen, PersonRights right)
	: m_id(id)
	, m_rights(right)
{
    setName(name, namelen);
}

PersonBase::PersonBase(const PersonBase &pb)
	: m_id(pb.m_id)
	, m_rights(pb.m_rights)
{
    strcpy(m_name, pb.m_name);
}

void PersonBase::setName(const char* name, int namelen)
{
    int lenth = (namelen < MAXLEN_NAME - 1) ? namelen : (MAXLEN_NAME - 1);
    for (int i = 0; i < lenth; ++i) {
		m_name[i] = name[i];
    }
	m_name[lenth] = 0;
}

void PersonBase::display()
{
    printf("name: %s, id: %d, right: %d\n", m_name, m_id, m_rights);
}